<?php

namespace App\Http\Controllers\Test;

use Illuminate\Http\Request;
use Reheat\Core\Standard\stdReturn;
use Biz\Criteria\User\EmailCriterion;
use Biz\Repositories\User\UserRepository;

/**
 * RepositoryController.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class RepositoryController extends Controller
{
    /**
     * @var \Lumen\Repository\Contracts\RepositoryContract
     */
    protected $repository;

    /**
     * RepositoryController constructor.
     *
     * @param UserRepository $repository
     */
    public function __construct(UserRepository $repository)
    {
        $this->repository = $repository;
    }

    /**
     * Home.
     *
     * @return string
     */
    public function index()
    {
        $email = 'Yang.jmj@gmail.com';

        return $this->repository
            ->setCacheLifetime(0)
            ->pushCriterion(new EmailCriterion($email))
            ->findFirst();
    }

    /**
     * Create.
     *
     * @param Request $request
     *
     * @return string
     */
    public function store(Request $request)
    {
        //数据验证
        $this->validate($request, [
            'mobile'            => 'required|regex:/^1[2345789][0-9]{9}$/',
            'password'          => 'required|min:5|max:32',
            'verification_code' => 'required|integer|max:999999',
            'contact'           => 'required|max:32',
            'institution'       => 'required|max:128',
        ]);

        // 数据获取
        $input = $request->all();

        $user = $this->repository->create($request->all());

        $std = new stdReturn();

        return $std->setData($user);
    }
}
